package com.baomidou.springwind.controller.data;

import com.baomidou.kisso.annotation.Permission;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springwind.controller.BaseController;
import com.baomidou.springwind.entity.Project;
import com.baomidou.springwind.entity.ReceiveGoods;
import com.baomidou.springwind.service.ProjectService;
import com.baomidou.springwind.service.ReceiveGoodsService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;

/**
 * <p>
 * 入库数据控制器
 * </p>
 *
 * @Author demo
 * @Date 2017/06/18
 */
@Controller
@RequestMapping("/receiveGoods")
public class ReceiveGoodsController extends BaseController {

    @Autowired
    private ReceiveGoodsService receiveGoodsService;

    @Autowired
    private ProjectService projectService;

    @Permission("1001")
    @RequestMapping("/list")
    public String list(Model model) {
        EntityWrapper<Project> wrapper = new EntityWrapper<Project>();
        wrapper.in("state", Arrays.asList("1", "2"));
        model.addAttribute("prjList", projectService.selectList(wrapper));
        return pjaxPath("/file/receive_goods_list", model);
    }

    @ResponseBody
    @Permission("1001")
    @RequestMapping("/getData")
    public String getData(Page<ReceiveGoods> page) {
        page = new Page<ReceiveGoods>(page.getCurrent(),page.getSize());
        EntityWrapper<ReceiveGoods> wrapper = new EntityWrapper<ReceiveGoods>();
        wrapper.eq("operator_id", getCurrentUserId());
        if (StringUtils.isNotEmpty(request.getParameter("batchId"))) {
            wrapper.eq("batch_id", request.getParameter("batchId"));
        }
        wrapper.orderBy("create_time", false);
        return jsonPage(receiveGoodsService.selectPage(page, wrapper));
    }
}
